package fule.com.playandroidkotlin.ui.activity

import android.content.Intent
import androidx.viewpager.widget.PagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import fule.com.playandroidkotlin.base.BaseActivity
import fule.com.kotlindemo.base.BaseView
import fule.com.playandroidkotlin.R
import fule.com.playandroidkotlin.base.BasePresenter
import kotlinx.android.synthetic.main.activity_welcome.*
import java.util.*

/**
 * 作者： njb
 * 时间： 2018/10/29 0029-下午 4:16
 * 描述： 欢迎页
 * 来源：
 */
class WelcomeActivity : BaseActivity<BasePresenter<BaseView>>() {
    private var imgRes: ArrayList<View>? = null

    override val layoutId: Int
        get() = R.layout.activity_welcome

    override fun createPresenter(): BasePresenter<BaseView> {
        return BasePresenter(this)
    }

    override fun initView() {
        imgRes = ArrayList()
        val wel1 = LayoutInflater.from(context).inflate(R.layout.activity_welcome1, null)
        val wel2 = LayoutInflater.from(context).inflate(R.layout.activity_welcome2, null)
        val wel3 = LayoutInflater.from(context).inflate(R.layout.activity_welcome3, null)
        val wel4 = LayoutInflater.from(context).inflate(R.layout.activity_welcome4, null)
        imgRes!!.add(wel1)
        imgRes!!.add(wel2)
        imgRes!!.add(wel3)
        imgRes!!.add(wel4)

        viewPager!!.adapter = WelAdapter()
        wel4.setOnClickListener {
            startActivity(Intent(context, MainActivity::class.java))

            finish()
        }
    }

    override fun addListener() {
    }

    override fun showLoading() {
    }

    override fun hideLoading() {
    }

    internal inner class WelAdapter : PagerAdapter() {
        override fun getCount(): Int {
            return imgRes!!.size
        }

        override fun isViewFromObject(view: View, `object`: Any): Boolean {
            return view === `object`
        }

        override fun instantiateItem(container: ViewGroup, position: Int): Any {
            val view = imgRes!!.get(position)
            container.addView(view)
            return view
        }

        override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
            container.removeView(`object` as View)
        }
    }

}
